package com.bc.bczbweb.controller;

import com.bc.bcapi.service.T_CountryService;
import com.bc.bccore.util.PageHelper;
import com.bc.bccore.zbconfig.ZbConfig;
import com.bc.bcmodel.domain.T_CountryModel;
import com.bc.bcmodel.req.MngUserBuyerListReq;
import com.bc.commoncore.util.ParseHelper;
import com.bc.commoncore.util.StringUtils;
import com.bc.commonentity.common.JsonResult;
import com.bc.bcapi.service.T_User_buyer_infoService;
import com.bc.bcmodel.domain.T_User_buyer_infoModel;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigInteger;

@Controller
@RequestMapping("t_user_buyer_info")
public class T_User_buyer_infoController extends BaseController {
    @Autowired
    T_User_buyer_infoService t_User_buyer_infoService;
    @Autowired
    T_CountryService t_countryService;

    @RequestMapping("list")
    public ModelAndView list() {
        ModelAndView view = super.baseView("列表", "t_user_buyer_info/list");
        return view;
    }

    @RequestMapping("listdo")
    public ModelAndView listdo(MngUserBuyerListReq req) {
        ModelAndView view = super.baseViewAjax("列表", "t_user_buyer_info/listdo");
        PageInfo<T_User_buyer_infoModel> pageInfo = t_User_buyer_infoService.getList(req);
        view.addObject("data", pageInfo.getList());
        view.addObject("page", PageHelper.GetAjaxHtml(pageInfo, "javascript:loadpage(##);"));
        return view;
    }

    @RequestMapping("add")
    public ModelAndView add(String user_id) {
        String title = "查看";
        ModelAndView view = super.baseView(title, "t_user_buyer_info/add");
        T_User_buyer_infoModel model = new T_User_buyer_infoModel();
        model.setUser_id(user_id);
        T_User_buyer_infoModel data = t_User_buyer_infoService.findByNamedParam(model);
        String countryName = "";
        int countryId = ParseHelper.ToInt(data.getCountry(), 0);
        if (countryId > 0) {

            T_CountryModel t_countryModel = new T_CountryModel();
            t_countryModel.setCountry_id(BigInteger.valueOf(countryId));
            T_CountryModel t_countryModelResult = t_countryService.findByNamedParam(t_countryModel);
            if (t_countryModelResult != null) {
                countryName = t_countryModelResult.getName_cn();
            }
        }
        view.addObject("data", data);
        view.addObject("country_name", countryName);
        view.addObject("title", title);
        view.addObject("imgurl", ZbConfig.getImgUrl());
        return view;
    }
}